#encoding:ISO-8859-1
'''
Created on 2012-9-28

@author: liuliangxiang01
'''
from xlrd import open_workbook  
import os, sys 
reload(sys)

trackDict={}
listPersons=[] 
trackName=""
wb = open_workbook('pc.xlsx')  
f = open("pc.html", "w")
f.writelines("<html ><head><meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'><title>sabrina</title></head><body>")
  
for s in wb.sheets():  
    for row in range(s.nrows):
        person={"fristname":"chengjie","lastname":"sabrina","organization":"njupt"}  
        for col in range(s.ncols):
            try:
                temp = s.cell(row, col).value
                if(col==0):
                    firstnameItem={"fristname":str(temp)}
                    person.update(firstnameItem)
                if(col==1):
                    lastnameItem={"lastname":str(temp)}
                    person.update(lastnameItem)
                if(col==4):
                    organizationItem={"organization":str(temp)}
                    person.update(organizationItem)
                if(col==6):
                    trackName=str(temp)
            except:
                continue
             
            
        if(trackName!=''):
            if(trackName in trackDict.keys()):
                listPersons=trackDict.get(trackName)
                listPersons.apuuuuuuuupend(person)
                updatePeopleDict={trackName:listPersons}
                trackDict.update(updatePeopleDict)
            elif(trackName not in trackDict.keys()):
                listPersons=[]
                listPersons.append(person)
                updatePeopleDict={trackName:listPersons}
                trackDict.update(updatePeopleDict)
for key in trackDict:
    f.writelines("<h1>"+key+"</h1>")
    listPersons=trackDict.get(key)
    f.writelines("<div>")
    for person in listPersons:
        f.writelines("<li>"+person.get("fristname")+","+person.get("lastname")+","+person.get("organization")+"</li>")
    f.writelines("</div>")
    
f.writelines("</body></html>")
f.close()

